
<%@ page language="java" contentType="text/html; charset=UTF-8"
	import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
	<form method="get">
		p1:<input type="text" name="p1" value="参数一的值" /><br />
		<br /> p2:<input type="text" name="p2" value="参数2的值" /><br />
		<br /> p3:<input type="text" name="p3" value="参数3的值" /><br />
		<br /> p4:<input type="text" name="p4" value="参数4的值" /><br />
		<br /> p5:<input type="checkbox" name="p5" value="参数5的值1" /><br />
		<br /> p5:<input type="checkbox" name="p5" value="参数5的值2" /><br />
		<br /> p5:<input type="checkbox" name="p5" value="参数5的值3" /><br />
		<br /> <input type="submit" value="提 交" />
	</form>
	<% 
	response.setContentType("text/html;charset=UTF-8");
	//request.setCharacterEncoding("UTF-8");	
	//设置两个域变量 p5和p6
	request.setAttribute("p6", "参数6的值");
	request.setAttribute("p7", "参数7的值");
	request.setAttribute("p8", "参数8的值");
	
	request.removeAttribute("p7");
	
	request.setAttribute("p8", "参数8修改后的值");
	

	out.println("1.---------输出所有客户端提交参数---------<br/><br/>");
	//输出所有客户端提交及参数的值
	out.print("p1 : "+request.getParameter("p1")+"<br/>");
	out.print("p2 : "+request.getParameter("p2")+"<br/>");
	out.print("p3 : "+request.getParameter("p3")+"<br/>");
	out.print("p4 : "+request.getParameter("p4")+"<br/>");
	
	out.println("<br/>");
	out.println("2.---------输出所有域变量---------<br/><br/>");
	//输出所有域变量的参数及参数的值
	out.println("p6: "+request.getAttribute("p6"));
	out.println("<br/>p7: "+request.getAttribute("p7"));
	out.println("<br/>p8: "+request.getAttribute("p8"));
	out.println("<br/>");
	out.println("<br/>");
	out.println("3.---------获取p5多值参数---------<br/><br/>");
	//输出p5多值参数的值，用逗号分隔开
	out.print("p5 : ");
	if(request.getParameterValues("p5")!=null)
		for(String a:request.getParameterValues("p5")){
			out.print(a+" , ");
		}
	out.println("<br/>"); 
	out.println("<br/>");
	out.println("4.---------获取HTTP Header---------<br/><br/>");
	Enumeration<String> headers = request.getHeaderNames();
	//输出所有HTTP头信息
	Enumeration<String> e = request.getHeaderNames();
	while(e.hasMoreElements()){
		String t = (String)e.nextElement();
		out.print(t+"  :  "+request.getHeader(t)+"<br/>");
	}
	out.println("<br/>");
	out.println("<br/>");
	out.println("5.---------获取cookie---------<br/><br/>");
	
	//设置Cookie
	
	Cookie msg1=new Cookie("login","tom");
	msg1.setMaxAge(30*24*60*60);
	response.addCookie(msg1);
	
	Cookie msg2=new Cookie("book","Java-EE");
	msg2.setMaxAge(30*24*60*60);
	response.addCookie(msg2);

	//输入所有Cookie信息
	Cookie c[]=request.getCookies();
	if(c==null){
		out.print("没有返回cookie<br/>");
	}else{
		for(Cookie ce:c){
			out.print(ce.getName()+" : "+ce.getValue()+"<br/>");
		}
	}
	
	out.println("<br/>");
	out.println("<br/>");
	out.println("6.---------其他方法---------<br/><br/>");	
	
	out.print("request.getRequestURL():" + request.getRequestURL() + "<br/>");
	out.print("request.getProtocol():" + request.getProtocol() + "<br/>");
	out.print("request.getRemoteAddr():" + request.getRemoteAddr()+ "<br/>");
	out.print("request.getRemoteHost():" + request.getRemoteHost() + "<br/>");
	out.print("request.getRemoteUser():" + request.getRemoteUser() + "<br/>");
	out.print("request.getServerName():" + request.getServerName() + "<br/>");
	out.print("request.getServerPort():" + request.getServerPort() + "<br/>");
	out.print("request.getContentLength():" + request.getContentLength() + "<br/>");
	out.print("request.getContentType():" + request.getContentType() + "<br/>");
	out.print("request.getQueryString():" + request.getQueryString() + "<br/>");
	out.print("request.getSession():" + request.getSession() + "<br/>");
	out.print("request.getServletPath():" + request.getServletPath() + "<br/>");

%>
</body>
</html>
